package com.micro.fast.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.PathSelectors.regex;

/**
 * @author lsy
 * swagger文档生成配置
 */
@Configuration
@EnableSwagger2
public class SwaggerUiConfig {
  @Bean
  public Docket testApi() {
    return new Docket(DocumentationType.SPRING_WEB)
        .groupName("portalUser")
        .genericModelSubstitutes(DeferredResult.class)
        //.genericModelSubstitutes(ResponseEntity.class)
        .useDefaultResponseMessages(false)
        .forCodeGeneration(true)
        // base，最终调用接口后会和paths拼接在一起
        .pathMapping("/")
        .select()
        //需要进行写入文档的接口
        .paths(or(regex("/tesco/user/.*")))
        .build()
        .apiInfo(portalUserApiInfo());
  }

  private ApiInfo portalUserApiInfo() {
    return new ApiInfoBuilder()
        //大标题
        .title("MS系统文档")
        //详细描述
        .description("系统接口说明")
        //版本
        .version("0.0.1-SNAPSHOT")
        .termsOfServiceUrl("NO terms of service")
        //作者
        .contact(new Contact("李守余", "http://kklt1996.gitee.io/blog/", "18332763730@163.com"))
        .license("The Apache License, Version 2.0")
        .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
        .build();
  }

}
